package com.example.administrator.caigou51.global;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.example.administrator.caigou51.activity.ChatActivityEmpty;


public class NotifyUnReadMsg
{
	private static NotifyUnReadMsg mNotifyUnReadMsg = null;

	public static NotifyUnReadMsg getInstance(Context context)
	{
		if (mNotifyUnReadMsg == null)
			mNotifyUnReadMsg = new NotifyUnReadMsg(context);

		return mNotifyUnReadMsg;
	}

	Context context;
	
	NotificationManager notificationManager;
	
	private NotifyUnReadMsg(Context context)
	{
		this.context = context;
	}

	@SuppressWarnings({ "deprecation", "rawtypes" })
	public void setNotiType(int iconId, String contentTitle, String contentText, Class activity)
	{
		notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
		
		Intent notifyIntent = new Intent(context, activity); // 创建新的Intent，作为点击Notification留言条时，会运行的Activity
		 
		PendingIntent appIntent = PendingIntent.getActivity(context, 0, notifyIntent, 0);// 创建PendingIntent作为设置递延运行的Activity
		
/*		Notification myNoti = new Notification(); // 创建Notication，并设置相关参数
		myNoti.flags = Notification.FLAG_AUTO_CANCEL; // 点击自动消失
		myNoti.icon = iconId; // 设置statusbar显示的icon
		myNoti.tickerText = contentTitle; // 设置statusbar显示的文字信息

		myNoti.setLatestEventInfo(context, contentTitle, contentText, appIntent);// 设置Notification留言条的参数*/
		Notification notification = new Notification.Builder(context)
				.setAutoCancel(true)
				.setContentTitle(contentTitle)
				.setContentText(contentText)
				.setContentIntent(appIntent)
				.setSmallIcon(iconId)
				.setWhen(System.currentTimeMillis())
				.build();

		notification.defaults = Notification.DEFAULT_VIBRATE;// 设置默认震动
		
		notificationManager.notify(0, notification);// 送出Notification
	}
	public void setNotiToChat(int iconId, String contentTitle, String contentText, Class activity,final String settingid, final String settingname,
							  String userid, String msgcontent, final int messagecount)
	{
		notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

		Intent notifyIntent = new Intent(context, activity); // 创建新的Intent，作为点击Notification留言条时，会运行的Activity
		notifyIntent.putExtra(ChatActivityEmpty.settingidString,settingid);
		notifyIntent.putExtra(ChatActivityEmpty.kidString,settingname);
		PendingIntent appIntent = PendingIntent.getActivity(context, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);// 创建PendingIntent作为设置递延运行的Activity

		Notification notification = new Notification.Builder(context)
				.setAutoCancel(true)
				.setContentTitle(contentTitle)
				.setContentText(contentText)
				.setContentIntent(appIntent)
				.setSmallIcon(iconId)
				.setWhen(System.currentTimeMillis())
				.build();

		notification.defaults = Notification.DEFAULT_VIBRATE;// 设置默认震动

		notificationManager.notify(0, notification);// 送出Notification

	//	notificationManager.notify(0, myNoti);// 送出Notification
	}
	public void dissmissNotifyCation()
	{
		if(notificationManager != null)
			notificationManager.cancel(0);
	}
}
